package com.khyr.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.khyr.Vo.LogVo;
import com.khyr.Vo.PurcharserVo3;
import com.khyr.Vo.PurchaseVo;
import com.khyr.Vo.PurchaserVo2;
import com.khyr.entity.StockInventoryLog;
import com.khyr.entity.StockPurchase;
import com.khyr.service.MedicinesService;
import com.khyr.service.PurChaseInVentoryLogService;
import com.khyr.service.PurchaseService;
import com.khyr.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @className: PurchaseController
 * @author: Zyl
 * @date: 2025/3/13 14:52
 * @Version: 1.0
 * @description:
 */
@RestController
@RequestMapping("/erp/purchase")
public class PurchaseController {
    @Autowired
    private PurchaseService purchaseService;
    @Autowired
    private PurChaseInVentoryLogService  purChaseInVentoryLogService;
    @Autowired
    private MedicinesService medicinesService;
    //分页-----查询药品采购业务
    @PostMapping("/listPurchaseForPage")
    public R<Page<StockPurchase>> listPurchaseForPage(@RequestBody PurchaseVo data) {
        return purchaseService.findPurchase(data);
    }
    //生成单据号-新增采购页面
    @GetMapping("/generatePurchaseId")
    public R  generatePurchaseId() {
        return purchaseService.generatePurchaseId();
    }
    // 1.添加采购单和详情【新增采购页面】
    @PostMapping("/addPurchase")
    public R addPurchase(@RequestBody PurchaserVo2 data) {
        return purchaseService.addPurchase(data);
    }
    //入库审核的界面--分页
    @PostMapping("/listPurchasePendingForPage")
    public R<Page<StockPurchase>> listPurchasePendingForPage(@RequestBody PurchaseVo data) {
        return purchaseService.findPurchase2(data);
    }
    // 根据采购单ID查询采购单信息和详情
    @GetMapping("/queryPurchaseAndItemByPurchaseId/{purchaseId}")
    public R<PurcharserVo3> queryPurchaseAndItemByPurchaseId(@PathVariable String purchaseId) {
        return purchaseService.queryPurchaseAndItemByPurchaseId(purchaseId);
    }
    // 提交审核【主页面】
    @PostMapping("/doAudit/{purchaseId}")
    public R doInvalid(@PathVariable String purchaseId) {
        return purchaseService.doInvalid(purchaseId);
    }
    //2. 添加采购单和详情---------并提交审核-------【新增采购页面】
    @PostMapping("/addPurchaseToAudit")
    public R addPurchaseToAudit(@RequestBody PurchaserVo2 data) {
        return purchaseService.addPurchase2(data);
    }
    //作废主页面
    @PostMapping("/doInvalid/{purchaseId}")
    public R del(@PathVariable String purchaseId) {
        return purchaseService.del(purchaseId);
    }
    //提交入库
    @PostMapping("/doInventory/{purchaseId}")
    public R doInventory(@PathVariable String purchaseId) {
        return purchaseService.doInventory(purchaseId);
    }
    // 审核不通过【根据采购单号】
    @PostMapping("/auditNoPass/{purchaseId}/{auditMsg}")
    public R auditNoPass(@PathVariable String purchaseId, @PathVariable String auditMsg) {
        return purchaseService.auditNoPass(purchaseId, auditMsg);
    }
    //点击订单后可以再次修改暂存
    @PostMapping("/erpAddPurchase")
    public R erpAddPurchase(@RequestBody PurchaserVo2 data) {
        return purchaseService.up(data);
    }
    //点击订单后可以再次提交审核
    @PostMapping("/erpAddPurchaseToAudit")
    public R erpAddPurchase2(@RequestBody PurchaserVo2 data) {
        return purchaseService.up2(data);
    }
    //审核通过
    @PostMapping("/auditPass/{purchaseId}")
    public R auditPass(@PathVariable String purchaseId) {
        return purchaseService.auditPass(purchaseId);
    }
    //分页查询所有的入库数据
    @PostMapping("/listInventoryLogForPage")
    public R<Page<StockInventoryLog>> listInventoryLogForPage(@RequestBody LogVo data) {
        return purChaseInVentoryLogService.find(data);
    }
}




